package com.garen.fire.web;

import com.garen.fire.biz.IFireCarGpsBiz;
import com.garen.fire.entity.FireCarGps;
import com.garen.fire.entity.FireCaseInfo;

import org.springframework.stereotype.Controller;

import java.util.Calendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.garen.common.*;
import org.springframework.web.servlet.ModelAndView;

import com.garen.sys.entity.FireUser;
import com.garen.sys.filter.SysFilter;

@Controller
@RequestMapping("/fire")
public final class FireCarGpsAction extends BaseAction {

	protected static Log log = LogFactory.getLog(FireCarGpsAction.class);

	@Autowired
	private IFireCarGpsBiz iFireCarGpsBiz;

	@RequestMapping("/firecargps/json")
	public ModelAndView json(PageBean<FireCarGps> pb, FireCarGps fireCarGps) {
		iFireCarGpsBiz.getFireCarGpsList(pb, fireCarGps);
		return Json(pb);
	}

	// 获取最新记录
	@RequestMapping("/firecargps/last")
	public ModelAndView last(Integer orgId) {
		FireUser user = getSessionUser();
		MsgBean mbean = SysFilter.getMsgBean();
		if (orgId == null)
			orgId = user.getUserOrgId();
		mbean.setObj(iFireCarGpsBiz.getFireCarGpsList(orgId));
		System.out.println(Json(mbean));
		return Json(mbean);
	}
	// 获取最新记录
		@RequestMapping("/firecargps/lastbuall")
		public ModelAndView lastbuall(Integer orgId) {
			FireUser user = getSessionUser();
			MsgBean mbean = SysFilter.getMsgBean();
			if (orgId == null)
				orgId = user.getUserOrgId();
			mbean.setObj(iFireCarGpsBiz.getFireCarGpsListbyAll(orgId));
			System.out.println(Json(mbean));
			return Json(mbean);
		}
	// 获取作战车辆id
	@RequestMapping("/firecargps/getFireCarGpsListByZd")
	public ModelAndView getFireCarGpsListByZd(FireCaseInfo fireCaseInfo) {

		MsgBean mbean = SysFilter.getMsgBean();
		FireUser user = getSessionUser();
		Calendar cale = Calendar.getInstance();
		cale.add(Calendar.HOUR, (int) (-12));
		fireCaseInfo.setBjsj(cale.getTime());
		Integer orgId = fireCaseInfo.getOrgId();
		if (orgId == null)
			orgId = user.getUserOrgId();
		mbean.setObj(iFireCarGpsBiz.getFireCarGpsListByZd(fireCaseInfo, orgId));
		return Json(mbean);

	}

	@RequestMapping("/firecargps/boxJson")
	public ModelAndView boxJson(FireCarGps fireCarGps) {
		return Json(iFireCarGpsBiz.getFireCarGpsList(fireCarGps));
	}

	@RequestMapping("/firecargps/edit")
	public ModelAndView edit(ModelAndView mav, FireCarGps fireCarGps) {
		mav.setViewName("fire/FireCarGpsEdit");
		if (fireCarGps.getGpsId() != null) {
			fireCarGps = iFireCarGpsBiz.getFireCarGps(fireCarGps);
		}
		mav.addObject("fireCarGps", fireCarGps);
		return mav;
	}

	@RequestMapping("/firecargps/save")
	public ModelAndView save(FireCarGps fireCarGps) {
		MsgBean mbean = SysFilter.getMsgBean(0, "保存成功 !");
		iFireCarGpsBiz.saveFireCarGps(mbean, fireCarGps);
		return Json(mbean);
	}

	@RequestMapping("/firecargps/del")
	public ModelAndView del(FireCarGps fireCarGps) {
		MsgBean mbean = SysFilter.getMsgBean(0, "删除成功 !");
		iFireCarGpsBiz.delFireCarGps(mbean, fireCarGps);
		return Json(mbean);
	}

}
